<template>
  <div>
    <el-form
      :model="form"
      :rules="rules"
      ref="ruleForm"
      v-loading="dloading"
      element-loading-text="操作时间较长，请稍后"
      element-loading-spinner="el-icon-loading"
    >
      <el-form-item
        label="封堵域名"
        :label-width="formLabelWidth"
        prop="domains "
      >
        <el-input v-model="form.domains" autocomplete="off"></el-input>
        <!-- <div>单ip示例:10.11.11.2</div> -->
        <!-- <div>多ip示例:10.11.11.2 10.11.11.3 10.11.11.4 (空格分开)</div> -->
      </el-form-item>
      <!-- <el-form-item
        label="instance"
        :label-width="formLabelWidth"
        prop="instance"
      >
        <el-input v-model="form.instance" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="mask" :label-width="formLabelWidth" prop="mask">
        <el-input v-model="form.mask" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="route" :label-width="formLabelWidth" prop="route">
        <el-input v-model="form.route" autocomplete="off"></el-input>
      </el-form-item> -->
      <!-- <el-form-item label="describe" :label-width="formLabelWidth"  prop="describe">
      <el-input v-model="form.describe" autocomplete="off"></el-input>
    </el-form-item> -->
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="cancel" :disabled="dloading">取 消</el-button>
      <!-- <el-button
        type="warning"
        @click="preview('ruleForm')"
        :disabled="dloading"
        >预 览</el-button
      > -->
      <el-button
        type="primary"
        @click="submitForm('ruleForm')"
        :disabled="dloading"
        >确 定</el-button
      >
    </div>
    <!-- 表格弹窗 -->
    <el-dialog
      title="预览"
      :visible.sync="dialogTableVisible"
      append-to-body
      v-loading="dloading"
      element-loading-text="操作时间较长，请稍后"
      element-loading-spinner="el-icon-loading"
    >
      <el-table :data="gridData" height="300px">
        <el-table-column label="数据预览" property="rewName"></el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogTableVisible = false" :disabled="dloading"
          >取 消</el-button
        >
        <el-button
          type="primary"
          @click="submitForm('ruleForm')"
          :disabled="dloading"
          >解 封</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { undo } from "@/api/fireWallRealm";
export default {
  name: "undo",
  props: {},
  data() {
    return {
      dialogTableVisible: false,
      gridData: [],
      dloading: false,
      form: {
        domains: "",
        // instance: "",
        // mask: "",
        // route: "",
        // describe:''
      },
      formLabelWidth: "120px",
      rules: {
        domains: [{ required: true, message: "请输入封堵域名 ", trigger: "blur" }],
        // instance: [
        //   { required: true, message: "请输入instance", trigger: "blur" },
        // ],
        // mask: [{ required: true, message: "请输入mask", trigger: "blur" }],
        // route: [{ required: true, message: "请输入route", trigger: "blur" }],
        // describe: [
        //   { required: true, message: '请输入describe', trigger: 'blur' }
        // ]
      },
    };
  },
  mounted() { },

  methods: {
    cancel() {
      this.$refs["ruleForm"].resetFields();
      // this.dialogFormVisible=false
      this.$emit("close", false);
    },
    submitForm(formName) {
      // debugger;
      this.$refs[formName].validate(async (valid) => {
        if (valid) {
          this.dloading = true;
          console.log("valid: ", valid);
          let form = this.form;
          console.log("form: ", form);
          let res = await undo(form);

          try {
            if (res.code === 1) {
              this.$message.success("操作成功");
              this.$emit("close", true);
              // this.dialogFormVisible=false
            }
            // debugger;
            this.dloading = false;
            console.log("解封res: ", res);
          } catch (err) {
            console.log("err", err);
            this.dloading = false;
          }
          // alert('submit!');
        } else {
          this.dloading = false;
          console.log("error submit!!");
          return false;
        }
      });
    },
    preview(formName) {
      // debugger;
      this.$refs[formName].validate(async (valid) => {
        if (valid) {
          this.dloading = true;
          console.log("valid: ", valid);
          let form = this.form;
          console.log("form: ", form);
          let res = await undorew(form);
          console.log('table-res: ', res);
          try {
            if (res.code === 1) {
              this.dialogTableVisible = true
              this.gridData = res.data.map(item => {
                return {
                  rewName: item
                }
              })
              // this.$message.success("操作成功");
              // this.$emit("close", true);
              // this.dialogFormVisible=false
            }
            // debugger;
            this.dloading = false;
            console.log("解封res: ", res);
          } catch (err) {
            console.log("err", err);
            this.dloading = false;
          }
          // alert('submit!');
        } else {
          this.dloading = false;
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>

<style scoped>
.dialog-footer {
  /* border: 1px solid red; */
  text-align: right;
}
</style>
